<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BookComments extends Model
{
    protected $table = 'book_comments';
    protected $casts = [
        'updated_at' => 'datetime:Y-m-d H:i:s',
        'created_at' => 'datetime:Y-m-d H:i:s',
    ];
    protected $fillable = [
        'module_id', 'pid', 'user_id', 'book_id', 'content'
    ];

    //评论属于某个用户
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    //评论属于某本书
    public function book()
    {
        return $this->belongsTo(Books::class);
    }

    public function start()
    {
        return $this->hasOne(BookCommentsStart::class, 'comments_id', 'id');
    }
}
